package com.tedu._09springaop.egaop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggerAspect {
    @Around("execution(public Boolean com.tedu._09springaop.egaop.CartServiceImpl.*(..))")
    public void aroundAdvice(ProceedingJoinPoint joinPoint) {

        try {
            System.out.println("[环绕通知]前置通知：开始添加购物车");
            Boolean a = (Boolean) joinPoint.proceed();
            if (a) {
                System.out.println("[环绕通知]返回通知: 添加购物车成功");
            } else {
                System.out.println("[环绕通知]返回通知: 添加购物车失败");
            }
        } catch (Throwable e) {
            System.out.println("[环绕通知]异常通知");
            throw new RuntimeException(e);
        } finally {
            System.out.println("[环绕通知]后置通知：操作完成");
        }

    }
}
